<template>
  <div class="app-container">
    <el-table
      :data="deviceCompanyHistoryList"
      style="width: 100%"
    >
      <el-table-column
        prop="userName"
        :label="$t('user')+$t('name')"
      />
      <el-table-column
        prop="deviceName"
        :label="$t('device')"
      />
      <el-table-column
        prop="companyName"
        :label="$t('company')"
      />
      <el-table-column
        :label="$t('time')"
      >
        <template slot-scope="scope">
          <i class="el-icon-time" />
          <span style="margin-left: 13px">{{
            formatDate(scope.row.createdDate)
          }}</span>
        </template>
      </el-table-column>
    </el-table>

  </div>
</template>
<script>
import {
  formatDate
} from '@/util/common'
import {
  pageGetDeviceCompanyHistory
} from '@/api/iot/iotDeviceCompanyHistoryApi'
import { getPageSize } from '@/util/storage'

export default {
  name: 'DeviceCompanyHistory',
  data() {
    return {
      deviceCompanyHistoryList: [],
      currentPage: 0,
      total: 0,
      pageSize: getPageSize()
    }
  }, created() {
    const param = this.$route.query
    this.deviceCore = param.deviceCore
    this.pageGetDeviceCompanyHistory()
    this.setTagsViewTitle()
  },
  methods: {
    setTagsViewTitle() {
      this.tempRoute = Object.assign({}, this.$route)
      const route = Object.assign({}, this.tempRoute, {
        title: `${this.deviceCore}`
      })
      this.$store.dispatch('tagsView/updateVisitedView', route)
    },
    formatDate(time) {
      return formatDate(this, time)
    },
    pageGetDeviceCompanyHistory() {
      pageGetDeviceCompanyHistory({
        pageSize: this.pageSize,
        currentPage: this.currentPage,
        deviceCore: this.deviceCore
      }).then(res => {
        const { code, data } = res
        if (code === '200') {
          this.total = data.total
          this.deviceCompanyHistoryList = data.data
        } else {
          this.total = 0
          this.deviceCompanyHistoryList = []
        }
      })
    }
  }
}
</script>


